using UnityEngine;
using UnityEngine.UI;
using Mirror;

public class MyNetworkManagerHUD : MonoBehaviour
{

    private NetworkManager networkManager; // 创建 NetworkManager 对象
    public GameObject btn;
    public GUISkin mySkin;
    private GameObject startHost;//启动网络主机按钮
    private GameObject startClient;//启动网络客户端按钮
    private GameObject stopHost;//停止网络主机或客户端按钮
    void Awake()
    {
        networkManager = FindObjectOfType<NetworkManager>();
        startHost = GameObject.Find("StartHost");
        startClient = GameObject.Find("StartClient");
        stopHost = GameObject.Find("StopHost");
        startHost.GetComponent<Button>().onClick.AddListener(OnStartHost);
        startClient.GetComponent<Button>().onClick.AddListener(StartClient);
        stopHost.GetComponent<Button>().onClick.AddListener(StopHost);
    }

    private void Update()
    {
        // GetComponent<NetworkManagerHUD>().enabled = true;

        if (!NetworkClient.isConnected && !NetworkServer.active) // 检查客户端和服务器的连接状态
        {
            startHost.SetActive(true);
            startClient.SetActive(true);
            stopHost.SetActive(false);
        }
        else
        {
            startHost.SetActive(false);
            startClient.SetActive(false);
            stopHost.SetActive(true);
        }

    }
     private void OnStartHost()
    {
        networkManager.StartHost(); // 启动网络主机
    }
    private void StartClient()
    {
        networkManager.StartClient(); // 启动网络客户端
    }
    private void StopHost()
    {
        networkManager.StopHost(); // 停止网络主机或客户端
    }
}
